<template>
<div class="comment">
  <el-table
    :data="list"
    style="width: 100% text-align : center">
    <el-table-column
      label="商品id"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.good_id }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="商品姓名"
      width="850"
      margin="0 auto"
      >
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>姓名: {{ scope.row.name }}</p>
          <p>住址: {{ scope.row.address }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.good_name }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">查看评论</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table> 
</div>
</template>
<script>
export default {
  data() {
    return {
      list:[],
      comment:'',
      id:""
    };
  },
  mounted() {
    console.log("1");
     console.log(this.list)
  },
  created() {
    this.init();
   
  },
  methods: {
    handleEdit(index, row) {
        console.log(index, row);
        this.axios({
          method:"post",
          url:"http://api_devs.wanxikeji.cn/api/admin/commentList",
          data:{
            token:this.$store.state.token,
            good_id:row.good_id
          }
        }).then((res)=>{
          console.log(res)
          if(res.data.data.list.length == 0){
             alert("暂无评论")
          }else {
            for(let i = 0 ; i < res.data.data.list.length; i++){
                this.comment += res.data.data.list[i].info 
            }
           alert(this.comment)
           this.comment = ''
          }
           
          
        })
      },
      handleDelete(index, row) {
        console.log(index, row);
        this.axios({
          method:"post",
          url:"http://api_devs.wanxikeji.cn/api/commentDel",
          data:{
            token:this.$store.state.token,
            id:this.id
          }
        }).then((res)=>{
          console.log(res)
        })
      },
    init() {
      this.axios({
        method: "post",
        url: "http://api_devs.wanxikeji.cn/api/admin/goodList",
        data: {
          token: this.$store.state.token,
          size: "1000",
          page: "1",
        },
      }).then((res) => {
        console.log(res);
        for(let i = 0 ; i < res.data.data.data.length; i++){
          this.list.push(res.data.data.data[i])
        }
         
      });
    },
  },
};
</script>
<style scoped>
</style>